/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa036is.validators;

import cz.muni.fi.pa036is.dto.ComplaintFormTO;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 *
 * @author Kuba
 */
public class ComplaintValidator implements Validator{

    @Override
    public boolean supports(Class<?> type) {
        return ComplaintFormTO.class.equals(type);
    }

    @Override
    public void validate(Object o, Errors errors) {

        ValidationUtils.rejectIfEmpty(errors, "text", "text.empty");
        
        ComplaintFormTO complaint = (ComplaintFormTO) o;


        if (complaint.getName().length() > 100) {
            errors.rejectValue("name", "name.value");
        }
        
        
    }
    
}
